﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Telerik.Charting;
using Windows.Globalization.NumberFormatting;
using Windows.UI.Xaml.Data;

namespace CityDashboard.Converters
{
    public class NumberFormatter
    {
        public static string Convert(double number)
        {
            return number.ToString("N", new CultureInfo("vi-VN"));
        }
        public static string Convert(int number)
        {
            return number.ToString("N0", new CultureInfo("vi-VN"));
        }
    }

    public class ChartNumberFormatter : IContentFormatter
    {

        public object Format(object owner, object content)
        {
            return NumberFormatter.Convert(double.Parse(content.ToString(), CultureInfo.CurrentCulture));
        }
    }

    public class NumberConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value is int)
                return NumberFormatter.Convert(int.Parse(value.ToString(), CultureInfo.CurrentCulture));
            return NumberFormatter.Convert(double.Parse(value.ToString(), CultureInfo.CurrentCulture));
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }

}
